/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import models.Paymethod;
import models.Student;
import models.User;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Achie
 */
public class PaymethodDao {

    private final Session session;

    public PaymethodDao(Session session) {
        this.session = session;
    }

    public List<Paymethod> findAll() {
        Transaction tx = session.beginTransaction();
        List<Paymethod> list = session.createQuery("from Paymethod").list();
        tx.commit();
        return list;
    }

    public boolean save(Paymethod paymethod) {
        try {
            Transaction tx = session.beginTransaction();
            session.save(paymethod);
            tx.commit();
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public boolean update(Paymethod paymethod) {
        try {
            Transaction tx = session.beginTransaction();
            session.update(paymethod);
            tx.commit();
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public Paymethod get(long id) {
        return (Paymethod) session.get(Paymethod.class, id);
    }

    public void delete(Paymethod paymethod) {
        Transaction tx = session.beginTransaction();
        session.delete(paymethod);
        tx.commit();
    }
    
}
